﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace application.forms
{
    public partial class copyDataOptions : common.forms.baseCopyDataOptions
    {
        public copyDataOptions()
        {
            InitializeComponent();
            dataKeyEd.isToUpperCase = true;
        }

        public delegate void OnDataTypeChanged();
        public event OnDataTypeChanged myOnDataTypeChanged;

        public class OptionInfo
        {
            public int SelectedTypeIndex = 0;
            public string DataKey = "";
            public bool isAppendToData = false;
        }
        public override object GetOptions()
        {
            OptionInfo info = new OptionInfo();
            info.SelectedTypeIndex = dataTypeCb.SelectedIndex;
            info.DataKey = dataKeyEd.Text.Trim();
            info.isAppendToData = withAppendChk.Checked;
            return info;
        }
        public override void SetOptions(object info)
        {
            OptionInfo value = (OptionInfo)info;
            dataTypeCb.SelectedIndex = (value.SelectedTypeIndex >= 0 && value.SelectedTypeIndex < dataTypeCb.Items.Count ? value.SelectedTypeIndex : -1);
            dataKeyEd.Text = value.DataKey;
            withAppendChk.Checked = value.isAppendToData;
        }

        public bool myDataTypeEnable
        {
            set
            {
                dataTypeCb.Enabled = value;
            }
            get
            {
                return dataTypeCb.Enabled;
            }
        }
        public bool myDataKeyEnable
        {
            set
            {
                dataKeyEd.Enabled = value;
            }
            get
            {
                return dataKeyEd.Enabled;
            }
        }
        public void SetDataTypes(string[] types)
        {
            dataTypeCb.Items.Clear();
            dataTypeCb.Items.AddRange(types);
            if (dataTypeCb.Items.Count > 0) dataTypeCb.SelectedIndex = 0;
        }
        private void dataTypeCb_SelectionChangeCommitted(object sender, EventArgs e)
        {
            try
            {
                if (myOnDataTypeChanged == null) return;
                myOnDataTypeChanged();
            }
            catch (Exception er)
            {
                this.ShowError(er);
            }
        }
    }
}
